package com.qf.vue2.web.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //判断是否登录
        Object user = request.getSession().getAttribute("user");
        if (user == null){

            //去到登录页面
            response.sendRedirect(request.getContextPath() + "/login.html");

            return false;
        }

        return true;
    }
}
